import request from '@/utils/request'
import { encrypt } from '@/utils/rsaEncrypt'

export function add(data) {
  return request({
    url: '/user/' + data.deptId,
    method: 'post',
    data
  })
}

export function del(data, deptId) {
  return request({
    url: '/user/' + deptId,
    method: 'delete',
    data
  })
}

export function edit(data) {
  return request({
    url: '/user/' + data.deptId,
    method: 'put',
    data
  })
}

export function editStatus(data) {
  return request({
    url: '/user/status',
    method: 'put',
    data
  })
}

export function getUser(id) {
  return request({
    url: '/user/' + id,
    method: 'get'
  })
}

export function listUser(params, page) {
  return request({
    url: '/user/list/' + page.pageNum + '/' + page.pageSize + '/' + page.currentDept,
    method: 'get',
    params
  })
}

export function updatePwd(user) {
  const data = {
    passWord: encrypt(user.passWord),
    newPassWord: encrypt(user.newPassWord)
  }
  return request({
    url: '/user/pwd',
    method: 'put',
    data
  })
}

export function editAvatar(data) {
  return request({
    url: '/user/avatar',
    method: 'post',
    data
  })
}

export function importUser(data) {
  return request({
    url: '/user/import',
    method: 'post',
    data
  })
}

export function exportUser() {
  return request({
    url: '/user/export',
    method: 'post',
    responseType: 'blob'
  })
}

export function findUserAndDept(params) {
  return request({
    url: '/user/and/dept',
    method: 'get',
    params
  })
}

export default { add, edit, del, listUser, getUser, updatePwd, editAvatar, importUser, exportUser, editStatus, findUserAndDept }

